const { UserDeviceModel } = require('../../models/models')


function addDevice(json = {}) {
    const { username, deviceId } = json;
    if (username && deviceId) {
        //update用户设备,用户每个设备信息唯一
        return new Promise((res, rej) => {
            UserDeviceModel.updateOne({ username,deviceId }, json, {
                upsert: true,
                muti: true
            })
                .then(docs => res(docs))
                .catch(err => {
                    console.log(err);
                    res({ status: 1 })
                });
        })

    } else {
        return ({ status: 1, data: '用户名设备号无效' })
    }


}

module.exports = addDevice;

